function [lpostd,likel,lpriord,lpriord_ss,flag_ok]=lmj_postmax(parest, parvec, parposest, funcmod, Y, trainvec, prpar, prss, solveopt, addsol, ssposest)
% ======================================================================
% LMJ_POSTMAX.M
% follow the structure of GENSYSPOST_VEC by Alejandro Justiniano (C)
% IN addition to putting priors on parameters, our current model put
% priors on steady state values.
% 
% AJ June 2010. Allow for mixed frequency if ADDSOL.FLAG_MIXFREQ==0 
% Solution depends on whether G is fixed or time varying, as in the case of
% a cummulator. Determined by ADDSOL.FLAG_GTV ==0 or GTV == 1 
% =======================================================================
lpostd=-1e15;
likel=[];lpriord=[];lpriord_ss=[]; 
flag_ok=0;
parvec(parposest)=parest;
%% Likelihood
switch addsol.flag_mixfreq
    case 0
        [likel, ssvec] = lmj_likel(parest, parvec, parposest, funcmod, Y, trainvec,solveopt, addsol);
    case 1 
        if addsol.flag_gtv == 1
            [likel, ssvec] = lmj_likel_tagtv_general(parest, parvec, parposest, funcmod, Y, trainvec, solveopt, addsol); 
        else
            [likel, ssvec] = lmj_likel_tagin(parest, parvec, parposest, funcmod, Y, trainvec, solveopt, addsol); 
        end 
end         
if abs(likel)==1e40; return; end
%% Prior Density of Parameters
lpriord=sum(priordens(parvec, prpar.prior, prpar.alphap, prpar.betap, prpar.lbnd, prpar.ubnd));
if isinf(abs(lpriord))==1;return;end
%% Prior Density on Steady State
if ~isempty(ssposest)
    lpriord_ss = sum(priordens(ssvec(ssposest), prss.prior, prss.alphap, prss.betap, prss.lbnd, prss.ubnd));
    if isinf(abs(lpriord_ss))==1;return;end
else
    lpriord_ss=0;
end
%% log likelihood
lpostd = lpriord + lpriord_ss + likel;
flag_ok=1;